package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//个人游记
@Setter
@Getter
public class Travel {
    public static final Integer StATE_REJECT = 0;//拒绝转态
    public static final Integer StATE_NORMAL = 1;//草稿
    public static final Integer StATE_WAITING = 2; //审核转态
    public static final Integer StATE_RELEASE = 3;//审核通过

    private Long id; //id

    private String title; //标题
    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime; // 旅游的时间

    private String perExpends;//人均消费

    private Integer days; //旅游天数

    private Integer person; //和谁旅游

    private User author; // 发布人
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime; //创建日期
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime; //发布日期

    private Boolean isPublic; //是否公开

    private Region place; //旅游地点

    private String coverUrl; //背景
    @JsonFormat(pattern = "yyyy-MM-dd hh-mm-ss",timezone = "GMT+8")
    private Date lastUpdateTime; //最后更新日期

    private int state = StATE_NORMAL; //状态 默认是编辑转态

    //游记内容和游记是一对一的关系
    private TravelContent travelContent;

    //点赞数
    private GreatCount greatCount;

    public String getStateDisplay(){
        if (state == StATE_REJECT){
            return "拒绝";
        }else if (state == StATE_NORMAL){
            return "草稿";
        }else if (state == StATE_WAITING){
            return "待发布";
        }else if (state == StATE_RELEASE){
            return "已发布";
        }else {
            return "";
        }
    }

    //编辑框的回显
    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",title);
        return JSONUtil.toJSONString(map);
    }

}